* This code produces Table A.3
clear all

use "../data/tab_a3_data.dta",clear

* define treatment zipcodes
gen treat = (chn_decile>=9)

clonevar hprice = p_singlefam

*deflate by cpi data from: https://www.minneapolisfed.org/about-us/monetary-policy/inflation-calculator/consumer-price-index-1913-
gen cpi=184 if year==2003
replace cpi=188.9 if year==2004
replace cpi=195.3 if year==2005
replace cpi=201.6 if year==2006
replace cpi=207.3 if year==2007
replace cpi=215.3 if year==2008
replace cpi=214.5 if year==2009
replace cpi=218.1 if year==2010
replace cpi=224.9 if year==2011
replace cpi=229.6 if year==2012
replace cpi=233 if year==2013
replace hprice=hprice/cpi //real price
gen lnhprice=ln(hprice)

*******************************************************************************
gen post_period=(year>=2008)
gen treat_post=treat*post_period

label var treat_post "Top Chn Region*Post"

foreach var in pop medinc density{	
    cap gen ln`var' = ln(`var')
}

global X "lnpop lnmedinc bachelorsshr lndensity"

*regression table
local i=1
foreach var in lnemp lnhprice{
	qui reg `var' treat_post post_period treat, cluster(zipcode)
	eststo reg`i'
	estadd local ctrl "No"
	estadd local zfe "No"
	estadd local tfe "No"
	qui reg `var'  treat_post post_period treat $X, cluster(zipcode)
	eststo reg`i'_1
	estadd local ctrl "Yes"
	estadd local zfe "No"
	estadd local tfe "No"
	qui reghdfe `var' treat_post, absorb(zipcode year) cluster(zipcode)
	eststo reg`i'_2
	estadd local ctrl "No"
	estadd local cfe "Yes"
	estadd local tfe "Yes"
	local ++i
}
esttab reg* using "../results/tableA3.tex", replace /// 
	keep(treat_post)  ///
	label ///
	star(* 0.10 ** 0.05 *** 0.01) /// 
	cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) ///
	stats(ctrl cfe zfe N, ///
		fmt(0 0 0 %11.0gc) ///
		labels( "Controls" ///
		    "ZIP code FE" /// 
			"Time FE" /// 
			"Obs." ///
			)) ///			
	mlabels(lnemp lnemp lnemp lnhprice lnhprice lnhprice) collabels(, none)  
eststo clear

